package MTT::Form::Fields;

use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
#with 'HTML::FormHandler::Render::Simple';
with 'HTML::FormHandler::Render::Simple';
use namespace::autoclean;

use utf8;

has schema => ( is => 'ro', required => 1);

has_field 'types' => ( type => 'Select', label => 'Типы' );
has_field 'fields' => ( type => 'Select', label => 'Поля');
has_field 'type' => ( type => 'Text', label => 'Тип');
has_field 'field' => ( type => 'Text', label => 'Поле' );
has_field 'name' => ( type => 'Text', label => 'Название' );
has_field 'short_name' => ( type => 'Text', label => 'Сокращенное название' );

has_field 'submit' => ( type => 'Submit', label => 'Сохранить' );

sub options_types {
	my ($self) = @_;

	my @options = ({value => '0', label => 'Новый'});
	foreach ( $self->schema->resultset('FieldName')->search({}, {columns => ['type'], distinct => 1}) ) {
		push @options, {value => $_->type, label => $_->type};
	}

	return @options;
}


__PACKAGE__->meta->make_immutable;
1;
